<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>16. lastindex属性的作用</title>
    </head>
    <body>
        <script type="text/javascript">
            let hd = "houdunren";
            // console.log(hd.match(/\w/g)); //["h", "o", "u", "d", "u", "n", "r", "e", "n"]
            let reg = /\w/g
            // console.log(reg.exec(hd));//["h", index: 0, input: "houdunren"]
            // console.log(reg.lastIndex);//1
            // console.log(reg.exec(hd));//["o", index: 1, input: "houdunren"]
            // console.log(reg.lastIndex); //2
            // console.log(reg.exec(hd));//["u", index: 2, input: "houdunren"]
            // console.log(reg.lastIndex);//3
            
            while(res=reg.exec(hd)){  //因为exec() 执行的过程中 lastIndex会自增
                console.log(res);
            }
        </script>
    </body>
</html>
